//
//  CJSplashGMAdapter.m
//  CJModileGMAdapter
//
//  Created by shanghailingye on 2024/4/24.
//

#import "CJSplashGMAdapter.h"

@interface CJSplashGMAdapter()<CJSplashAdDelegate>
/// 广告实例
@property (nonatomic, strong) CJSplashAd *splashAd;

@end

@implementation CJSplashGMAdapter

- (BUMMediatedAdStatus)mediatedAdStatus {
    return BUMMediatedAdStatusNormal;
}

- (void)dismissSplashAd {
    
}

- (void)loadSplashAdWithSlotID:(NSString *)slotID andParameter:(NSDictionary *)parameter {
    UIView *bottomView = [UIView new];
    if ([parameter valueForKey:BUMAdLoadingParamSPCustomBottomView] && [[parameter valueForKey:BUMAdLoadingParamSPCustomBottomView] isKindOfClass:[UIView class]]) {
        bottomView = [parameter valueForKey:BUMAdLoadingParamSPCustomBottomView];
    }
    self.splashAd = [[CJSplashAd alloc] initWithResourceId:slotID rootViewController:self.bridge.viewControllerForPresentingModalView customLogoView:bottomView];
    self.splashAd.delegate = self;
    [self.splashAd loadAdData];
}

- (void)showSplashAdInWindow:(UIWindow *)window parameter:(NSDictionary *)parameter {
    [self.splashAd showSplashAdToWindow:window];
}


- (void)didReceiveBidResult:(BUMMediaBidResult *)result {
}

#pragma mark CJSplashAdDelegate
- (void)splashAdDidLoad:(nonnull CJSplashAd *)splashAd resourceId:(nonnull NSString *)resourceId {
    NSInteger cpm = [self.splashAd getECpm];
    NSDictionary *ext = @{
        BUMMediaAdLoadingExtECPM : cpm ? [NSString stringWithFormat:@"%ld", cpm] : @"0",
    };
    [self.bridge splashAd:self didLoadWithExt:ext];
}

- (void)splashAdLoadFailed:(nonnull CJSplashAd *)splashAd error:(nonnull NSError *)error {
    [self.bridge splashAd:self didLoadFailWithError:error ext:@{}];
}

- (void)splashAdChannelOnShow:(CJSplashAd *)splashAd extraParams:(NSDictionary *)params {
    
}

- (void)splashAdChannelOnClicked:(CJSplashAd *)splashAd extraParams:(NSDictionary *)params {
    
}

- (void)splashAdOnClicked:(nonnull CJSplashAd *)splashAd {
    [self.bridge splashAdDidClick:self];
}

- (void)splashAdOnClosed:(nonnull CJSplashAd *)splashAd {
    [self.bridge splashAdDidClose:self];
}

- (void)splashAdOnShow:(nonnull CJSplashAd *)splashAd {
    [self.bridge splashAdWillVisible:self];
}




@end
